package com.project_doctor.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.project_doctor.pojo.AnnouncementReceiver;
import com.project_doctor.service.AnnouncementReceiverService;
import com.project_doctor.mapper.AnnouncementReceiverMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
* @author 龙龙与贝儿
* @description 针对表【t_announcement_receiver】的数据库操作Service实现
* @createDate 2025-06-05 15:54:28
*/
@Service
public class AnnouncementReceiverServiceImpl extends ServiceImpl<AnnouncementReceiverMapper, AnnouncementReceiver>
    implements AnnouncementReceiverService{
    @Autowired
    private AnnouncementReceiverMapper announcementReceiverMapper;
    @Override
    public void markAsRead(Long announcementId, Long receiverId) {
        LambdaUpdateWrapper<AnnouncementReceiver> wrapper = Wrappers.lambdaUpdate(AnnouncementReceiver.class)
                .eq(AnnouncementReceiver::getAnnouncementId, announcementId)
                .eq(AnnouncementReceiver::getReceiverId, receiverId)
                .set(AnnouncementReceiver::getReadStatus, 1);
        announcementReceiverMapper.update(null,wrapper);
    }

    @Override
    public List<AnnouncementReceiver> listForAnnReceiver(Long id) {
        List<AnnouncementReceiver> list = announcementReceiverMapper.selectListWithAnnSender(id);
        return list;
    }

    @Override
    public void deleteAnnReceiver(Long announcementId, Long receiverId) {
        LambdaQueryWrapper<AnnouncementReceiver> wrapper = Wrappers.lambdaQuery(AnnouncementReceiver.class)
                .eq(AnnouncementReceiver::getAnnouncementId, announcementId)
                .eq(AnnouncementReceiver::getReceiverId, receiverId);
        announcementReceiverMapper.delete(wrapper);
    }
}




